package inventoryservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/BeanUtils"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type InventoryAssetCheckoutEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInventoryAssetCheckoutEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InventoryAssetCheckoutEditLogic {
	return &InventoryAssetCheckoutEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// InventoryAssetCheckoutEdit 更新资产出库表项
func (l *InventoryAssetCheckoutEditLogic) InventoryAssetCheckoutEdit(in *property_service.InventoryAssetCheckout) (*property_service.Response, error) {
	// 获取资产出库表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).InventoryAssetCheckout
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、CreatedAt、UpdatedAt
	if _, err := do.UpdateColumns(&model.InventoryAssetCheckout{
		CheckoutCode:     in.CheckoutCode,                          // 出库单号
		CheckoutDate:     BeanUtils.GetDateFormat(in.CheckoutDate), // 出库日期
		Warehouse:        in.Warehouse,                             // 仓库
		Preparer:         in.Preparer,                              // 制单人
		WarehouseManager: in.WarehouseManager,                      // 仓管员
		UsingDept:        in.UsingDept,                             // 领用科室
		UsingDeptID:      in.UsingDeptID,                           // 领用科室ID
		Receiver:         in.Receiver,                              // 领用人
		ReceiverID:       in.ReceiverID,                            // 领用人ID
		Remarks:          in.Remarks,                               // 备注
		StatusID:         in.StatusID,                              // 状态ID
		StatusName:       in.StatusName,                            // 采购状态
		CheckoutStatus:   in.CheckoutStatus,                        // 状态
		StockID:          in.StockID,                               // 仓库ID
		UpdatedAtuser:    in.UpdatedAtuser,                         // 更新人
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
